package com.it.conformity.common.interceptor;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 自定义拦截器，拦截请求路径
 *
 * @Author: 王文龙
 * @Date: 2020/6/1917:18
 * @Version: 1.0
 * @Describe: 描述:用户拦截器
 */
@Component
public class RequestUrlInterceptor implements HandlerInterceptor {

    private Logger logger = LoggerFactory.getLogger(RequestUrlInterceptor.class);

    @Override

    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        logger.info("请求开始  --- Url : " + request.getRequestURI());
        return true;
    }

    @Override
    public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
        logger.info("请求结束");
        if (ex != null) {
            logger.error("报错信息 : ", ex);
        }
    }
}
